cmake_minimum_required(VERSION 3.5)

project(qtExe VERSION 0.1 LANGUAGES CXX)
find_package(Qt5 COMPONENTS Multimedia REQUIRED)

message("${QT5_DIR}")

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(qt_moduls Widgets Gui OpenGL Network Xml Svg Multimedia)
#set(qt_version_moduls)
#foreach(it ${qt_moduls})
#    list(APPEND qt_version_moduls Qt${QT_VERSION_MAJOR}::${it})
#    message("--->qt_moduls:" Qt${QT_VERSION_MAJOR}::${it})
#endforeach()

#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${qt_modules} REQUIRED)
set(qt_version_modules)
foreach(module ${qt_modules})
    list(APPEND qt_version_modules Qt${QT_VERSION_MAJOR}::${module})
endforeach()

#find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${qt_moduls})
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${qt_moduls}) # LinguistTools No link

set(PROJECT_SOURCES
        main.cpp
        chooseWindow.h
        chooseWindow.cpp
        chesspieces.h
        chesspieces.cpp
        chessstep.h
        chessstep.cpp
        chessvoice.h
        chessvoice.cpp
        chessboard.h
        chessboard.cpp
        chessboard.ui
        aboutauthor.h
        aboutauthor.cpp
        aboutauthor.ui
        machinegame.h
        machinegame.cpp
        networkgame.h
        networkgame.cpp
        resources/res.qrc
)

#************************************************* 拷贝 .ini 和资源文件 *******************************************************
# copy "resources" 文件夹下的指定文件夹
#set(folders_to_copy "licenses" "logo" "debian" "debian_portable")  # "cpack"
set(source_root "${CMAKE_SOURCE_DIR}/resources")
set(traget_root "${EXECUTABLE_OUTPUT_PATH}/resources")

# 遍历复制文件夹集合中的每个文件夹
#foreach(it ${folders_to_copy})
#    set(copy_source_dir "${source_root}/${it}")
#    file(COPY ${copy_source_dir} DESTINATION ${traget_root})
#endforeach()

#file(COPY "${CMAKE_SOURCE_DIR}/xconfig.ini" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
#******************************************* **********************************************

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(qtExe
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET qtExe APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(qtExe SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(qtExe
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(qtExe PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(qtExe PRIVATE ${qt_version_moduls})
target_link_libraries(qtExe PRIVATE Qt5::Multimedia)

set_target_properties(qtExe PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(qtExe)
endif()
